#include <func.h>

int main(int argc, char* argv[])
{
    int fd = open("a.txt", O_RDWR | O_CREAT | O_TRUNC, 0666);
    if (fd == -1) {
        perror("open()");
        exit(1);
    }

    pid_t pid = fork();
    switch (pid) {
    case -1:
        perror("fork()");
        exit(1);
    case 0:  // 子进程
        sleep(1);
        write(fd, "Hello world", 11);
        break;
    default: // 父进程
        printf("pos: %ld\n", lseek(fd, 0, SEEK_CUR));
        sleep(2);
        printf("pos: %ld\n", lseek(fd, 0, SEEK_CUR));
        break;
    }

    return 0;
}

